package blue.mqtt4j.internal.client.impl;

import blue.mqtt4j.client.ProducerResult;
import com.alibaba.fastjson.JSON;

/**
 * @author Jin Zheng
 * @since 1.0 2020-10-28
 */
public class DefaultProducerResult implements ProducerResult
{
	private int index;
	private boolean success;
	private Throwable cause;

	public DefaultProducerResult(int index, Throwable cause)
	{
		this.index = index;
		this.cause = cause;
		this.success = cause == null;
	}

	@Override
	public int index()
	{
		return index;
	}

	@Override
	public boolean isSuccess()
	{
		return success;
	}

	@Override
	public Throwable cause()
	{
		return cause;
	}

	@Override
	public String toString()
	{
		return JSON.toJSONString(this);
	}
}
